<template>
	<view class="container">
		<!-- 顶部导航栏 -->
<!-- 		<view class="nav-bar">
			<view class="left">
				<u-icon name="arrow-left" size="32" color="#333" @click="goBack"></u-icon>
			</view>
			<view class="title">排行榜</view>
			<view class="right"></view>
		</view> -->
		
		<!-- 我的排名卡片 -->
		<view class="my-rank">
			<view class="rank-num">
				<text class="num">{{myRank.rank}}</text>
				<text class="label">当前排名</text>
			</view>
			<view class="info">
				<image class="avatar" :src="myRank.avatar" mode="aspectFill"></image>
				<view class="detail">
					<text class="name">{{myRank.name}}</text>
					<text class="points">{{myRank.points}} 积分</text>
				</view>
			</view>
		</view>
		
		<!-- 排行榜列表 -->
		<view class="rank-list">
			<view class="tab-bar">
				<view class="tab" 
					v-for="(tab, index) in tabs" 
					:key="index"
					:class="{'active': currentTab === index}"
					@click="switchTab(index)">
					<text>{{tab}}</text>
				</view>
			</view>
			
			<view class="list">
				<view class="rank-item" v-for="(item, index) in rankList" :key="index">
					<view class="rank">
						<image v-if="index < 3" :src="'/static/rank-' + (index + 1) + '.png'" mode="aspectFit" class="rank-icon"></image>
						<text v-else class="rank-num">{{index + 1}}</text>
					</view>
					<image class="avatar" :src="item.avatar" mode="aspectFill"></image>
					<view class="info">
						<text class="name">{{item.name}}</text>
						<text class="points">{{item.points}} 积分</text>
					</view>
					<view class="trend" :class="item.trend">
						<u-icon :name="item.trend === 'up' ? 'arrow-up' : 'arrow-down'" size="24" :color="item.trend === 'up' ? '#52c41a' : '#ff4d4f'"></u-icon>
						<text>{{item.change}}</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 规则说明 -->
		<view class="rules">
			<view class="title">
				<u-icon name="info-circle" size="32" color="#666"></u-icon>
				<text>积分规则</text>
			</view>
			<view class="rule-list">
				<view class="rule-item" v-for="(rule, index) in rules" :key="index">
					<text class="dot">•</text>
					<text class="text">{{rule}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				myRank: {
					rank: 8,
					avatar: '/static/default-avatar.png',
					name: '未设置昵称',
					points: 2680
				},
				tabs: ['总榜', '周榜', '月榜'],
				currentTab: 0,
				rankList: [{
					avatar: '/static/default-avatar.png',
					name: '用户1',
					points: 5200,
					trend: 'up',
					change: 2
				}, {
					avatar: '/static/default-avatar.png',
					name: '用户2',
					points: 4800,
					trend: 'down',
					change: 1
				}, {
					avatar: '/static/default-avatar.png',
					name: '用户3',
					points: 4500,
					trend: 'up',
					change: 3
				}, {
					avatar: '/static/default-avatar.png',
					name: '用户4',
					points: 4200,
					trend: 'up',
					change: 1
				}, {
					avatar: '/static/default-avatar.png',
					name: '用户5',
					points: 3900,
					trend: 'down',
					change: 2
				}],
				rules: [
					'每日完成健康评估可获得10积分',
					'连续打卡可获得额外奖励积分',
					'参与健康行为测评可获得20积分',
					'完善个人信息可获得50积分',
					'邀请好友使用可获得100积分'
				]
			}
		},
		onShow() {
			// 获取用户信息
			const userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				const user = JSON.parse(userInfo)
				this.myRank.avatar = user.avatar || '/static/default-avatar.png'
				this.myRank.name = user.nickname || '未设置昵称'
			}
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			switchTab(index) {
				if (this.currentTab === index) return
				this.currentTab = index
				// 模拟切换数据
				uni.showLoading({
					title: '加载中...'
				})
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			}
		}
	}
</script>

<style lang="scss">
	.container {
		min-height: 100vh;
		background-color: #F7F7FA;
		
		.nav-bar {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 30rpx;
			background-color: #fff;
			
			.title {
				font-size: 36rpx;
				font-weight: bold;
				color: #333;
			}
		}
		
		.my-rank {
			margin: 30rpx;
			background-color: #fff;
			border-radius: 16rpx;
			padding: 30rpx;
			display: flex;
			align-items: center;
			
			.rank-num {
				margin-right: 40rpx;
				text-align: center;
				
				.num {
					font-size: 48rpx;
					font-weight: bold;
					color: #1890FF;
					display: block;
				}
				
				.label {
					font-size: 24rpx;
					color: #999;
					margin-top: 8rpx;
					display: block;
				}
			}
			
			.info {
				flex: 1;
				display: flex;
				align-items: center;
				
				.avatar {
					width: 80rpx;
					height: 80rpx;
					border-radius: 40rpx;
					margin-right: 20rpx;
				}
				
				.detail {
					.name {
						font-size: 32rpx;
						color: #333;
						font-weight: bold;
						display: block;
						margin-bottom: 8rpx;
					}
					
					.points {
						font-size: 28rpx;
						color: #666;
					}
				}
			}
		}
		
		.rank-list {
			margin: 30rpx;
			background-color: #fff;
			border-radius: 16rpx;
			
			.tab-bar {
				display: flex;
				padding: 20rpx;
				border-bottom: 2rpx solid #f5f5f5;
				
				.tab {
					flex: 1;
					height: 60rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					
					text {
						font-size: 28rpx;
						color: #666;
					}
					
					&.active {
						text {
							color: #1890FF;
							font-weight: bold;
						}
					}
				}
			}
			
			.list {
				.rank-item {
					display: flex;
					align-items: center;
					padding: 30rpx;
					border-bottom: 2rpx solid #f5f5f5;
					
					&:last-child {
						border-bottom: none;
					}
					
					.rank {
						width: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						
						.rank-icon {
							width: 40rpx;
							height: 40rpx;
						}
						
						.rank-num {
							font-size: 32rpx;
							font-weight: bold;
							color: #666;
						}
					}
					
					.avatar {
						width: 80rpx;
						height: 80rpx;
						border-radius: 40rpx;
						margin: 0 20rpx;
					}
					
					.info {
						flex: 1;
						
						.name {
							font-size: 28rpx;
							color: #333;
							display: block;
							margin-bottom: 8rpx;
						}
						
						.points {
							font-size: 24rpx;
							color: #666;
						}
					}
					
					.trend {
						display: flex;
						align-items: center;
						
						&.up {
							text {
								color: #52c41a;
							}
						}
						
						&.down {
							text {
								color: #ff4d4f;
							}
						}
						
						text {
							font-size: 24rpx;
							margin-left: 4rpx;
						}
					}
				}
			}
		}
		
		.rules {
			margin: 30rpx;
			background-color: #fff;
			border-radius: 16rpx;
			padding: 30rpx;
			
			.title {
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				
				text {
					font-size: 32rpx;
					font-weight: bold;
					color: #333;
					margin-left: 12rpx;
				}
			}
			
			.rule-list {
				.rule-item {
					display: flex;
					align-items: flex-start;
					margin-bottom: 16rpx;
					
					&:last-child {
						margin-bottom: 0;
					}
					
					.dot {
						font-size: 28rpx;
						color: #666;
						margin-right: 8rpx;
					}
					
					.text {
						font-size: 28rpx;
						color: #666;
						flex: 1;
						line-height: 1.5;
					}
				}
			}
		}
	}
</style> 